package com.sf.wisdomkg.adapter;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.sf.wisdomkg.utils.OnButtonCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class home_viewPaper_Adapter extends PagerAdapter {
    private List<View> mListViews;
    private Context context1;
    private ArrayList<HashMap<String, String>> Alist;
    private OnButtonCallback callback;

    public home_viewPaper_Adapter(Context context, List<View> mListViews,
                                  ArrayList<HashMap<String, String>> list,
                                  OnButtonCallback callback) {
        this.context1 = context;
        this.Alist = list;
        this.mListViews = mListViews;
        this.callback = callback;
    }

    @Override
    public int getCount() {

        return mListViews.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        // view和object是不是同一对象
        return arg0 == arg1;
    }

    // 实例化item
    @Override
    public Object instantiateItem(ViewGroup arg0, final int arg1) {
        // 将每个图片添加到viewPager里
        final View view = mListViews.get(arg1);

        arg0.addView(view);
        // view.setTag(Alist.get(arg1).get("url"));
        view.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

//                String id = Alist.get(arg1).get("goodId");
//                System.out.println("点击的id"+id);
//                Intent intent = new Intent(context1,ShopDetailActivity.class);
//                // 用Bundle携带数据
//                Bundle bundle = new Bundle();
//                bundle.putString("id", id);
//                intent.putExtras(bundle);
//                context1.startActivity(intent);
            }
        });
        return view;

    }

    @Override
    public void destroyItem(ViewGroup arg0, int arg1, Object arg2) {
        // 将每个图片在viewpager里释放掉
        arg0.removeView(mListViews.get(arg1));

    }

    @Override
    public void finishUpdate(View container) {
        // TODO Auto-generated method stub

    }

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // TODO Auto-generated method stub

    }

    @Override
    public Parcelable saveState() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void startUpdate(View container) {
        // TODO Auto-generated method stub

    }

}